Add Set-Like Operations to ElementArray#195
Conversation
|
@GamelinAl, @gubaidulinvadim I’ll let you take a look at the tests and check whether they suit your needs. |
|
@gupichon It works really well. I've made a quick test with examples/SOLEIL_examples config file where we have different cells defines. For some reason, for Union operation I could not do '|' but the '+' has worked. I've cut the beginning IPython cells where I defined the array and the output of the last IPython cell to have a readable example. Briefly looking at your tests, I don't see tests for | operation. |
|
For me it looks good. |
|
Yep, I completely forgot the | operator… |
gubaidulinvadim
left a comment
There was a problem hiding this comment.
Looks ok to me. I'd let @GamelinAl to do his review because I'm not at all a user with a lot of strong demands.
|
Could you use code block in your code snippet to get nice code in the doc ? .. code-block:: python
>>> hcorr = sr.live.get_magnets("HCORR")
>>> vcorr = sr.live.get_magnets("VCORR")
>>> all_corr = hcorr | vcorr |
Done |
|
The doc is still failing. I do not manage to include |
|
It’s the first time I’m working with Sphinx. It will be corrected in the next commit; I’ve managed to test it on my side. |
|
To test the doc: |
|
Ah yes, it is possible to link as well |
|
Yes, I just found where the issue was… Thanks for the commit. |
|
I think I cannot review as i did some commit. |
|
@JeanLucPons Alexis will make a review, he still may have a few comments. After we can merge. |
|
I have no comment directly linked to this PR, everything I tested seem to work fine. I have a few comments partially linked to this PR, up to you if we adress this here or if I should do a new issue.
From what I see, this is the case for all these methods, which prevent using the nice feature of the arrays.
|
|
Yes For the time being, you can create standalone arrays (no name, not added to a holder) like below ae = ElementArray("", sr.design.get_all_elements())
bpms = ae["BPM*"] # Returns a standalone BPM array (on design)or allBpms = BPMArray("", sr.design.get_all_bpms())We can propose convenience functions for standalone arrays: # Returns a standalone `BPMArray` without name and not added to the holder
bpms = Arrays.get( sr.design, "BPM*")
bpms = Arrays.get( sr.design.get_all_bpms() )
# or
bpms = sr.design.get_arrays( "BPM*")
bpms = sr.design.get_all_bpm_array( )We can also change the interface of Concerning documentation, it is progressing... |
|
@GamelinAl, @JeanLucPons, @gubaidulinvadim, I suggest we discuss these points in a separate discussion before opening an issue. I think the ACCML concept of YellowPages, in addition to PyAML arrays, can cover these requirements. |


Description
This PR introduces native set-like operations on
ElementArray, including support for boolean masks and automatic result typing.The goal is to make element selection more expressive, algebraic, and robust, while preserving type specialization (e.g.,
MagnetArray,BPMArray) even when filtering heterogeneous arrays.The following operators are now supported:
&→ intersection between arrays|→ union (unique, stable order)+→ alias for union-→ difference between arrays& mask→ boolean filtering (keep True)- mask→ boolean removal (remove True)Additionally, empty results now return a properly typed empty array instead of a Python list, ensuring safe chaining.
Related Issue
ElementArray#194Features described there are:
ElementArray&and-[]Changes to existing functionality
ElementArray.__auto_arrayreimplemented using nearest common ancestor resolution (MRO intersection) to correctly handle heterogeneous subclasses (e.g., multipleMagnetsubclasses now correctly produceMagnetArrayinstead ofElementArray).ElementArray.__create_arrayupdated to return typed empty arrays instead of raw[]to preserve method chaining.ElementArray.__init__updated to always initialize internal attributes (__peer,__use_aggregator) even when the array is empty.mask_by_type()to generate reusable boolean masks.filter_by_type(),of_type(), andexclude_type()as declarative filtering helpers.zip()calls updated to usestrict=True.These changes ensure:
zip()behavior.Testing
The following pytest-compatible tests were added:
&with Python boolean mask filters correctly&with NumPy boolean mask filters correctly-with boolean mask removes elements correctlyValueErrorMagnetreturnMagnetArray(nearest common ancestor logic)All tests pass locally.
Verify that your checklist complies with the project